<template>
  <div>
    <button type="button" class="back-top small" @click="backTop()" v-show="backTopShow">我要上天</button>
  </div>
</template>

<script scoped>
  export default {
    data() {
      return {
        backTopShow:false
      }
    },
    components: {},
    mounted() {
      window.addEventListener('scroll', this.handleScroll)
    },
    methods: {
      backTop() {
        let back = setInterval(() => {
          if(document.body.scrollTop||document.documentElement.scrollTop){
            document.body.scrollTop-=100;
            document.documentElement.scrollTop-=100;
          }else {
            clearInterval(back)
          }
        });
      },
      handleScroll(){
        if (document.documentElement.scrollTop + document.body.scrollTop > 100) {
          this.backTopShow=true;
        }
        else {
          this.backTopShow=false;
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .back-top {
    position: fixed;
    right: 10px;
    bottom: 10px
  }
</style>
--------------------- 
作者：阿之阿佐 
来源：CSDN 
原文：https://blog.csdn.net/u010214074/article/details/78751875 
版权声明：本文为博主原创文章，转载请附上博文链接！